package com.hcb.tonguetiphealth.widget.more;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import com.hcb.tonguetiphealth.adapter.ResListAdapter;
import com.hcb.tonguetiphealth.global.Global;
import com.hcb.tonguetiphealth.model.Restaurant;
import com.hcb.tonguetiphealth.view.R;
import com.hcb.tonguetiphealth.widget.BottomWidget;
import com.hcb.tonguetiphealth.widget.GeneralWidget;
import com.hcb.tonguetiphealth.widget.resbook.RestaurantBookInfoWidget;

public class HistoryWidget extends GeneralWidget implements OnClickListener {

	private Activity ctx;

	private LinearLayout llBack;
	private ListView resListView;


	public HistoryWidget(Context context) {
		super(context);
		ctx = (Activity) context;
		inflate(context, R.layout.more_history, this);

		new BottomWidget(context, this);
		bindView();
		bindEvent();
		initData();
	}

	private void bindView() {
		resListView = (ListView)findViewById(R.id.res_listview);
		llBack = (LinearLayout) findViewById(R.id.more_history_back);
	}

	private void bindEvent() {
		llBack.setOnClickListener(this);
		resListView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				// TODO Auto-generated method stub
				Restaurant res = (Restaurant) arg0.getAdapter().getItem(arg2);
 
				ctx.getIntent().putExtra("resId", res.getId());
				ctx.getIntent().putExtra("fromWidget", "HistoryWidget");
				ctx.setContentView(new RestaurantBookInfoWidget(ctx));
			}
		});
	}

	private void initData(){
		List<Restaurant> resList = new ArrayList<Restaurant>();
		resList = Global.recentResList;
		ResListAdapter adapter = new ResListAdapter(ctx, resList);
		resListView.setAdapter(adapter);
	}
	
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.more_history_back:
			ctx.setContentView(new MoreWidget(ctx));
			break;

		default:
			break;
		}
	}

	@Override
	public void notifyAdapter() {

	}
}
